//
//  WH_PastViewController.m
//  App_6.23
//
//  Created by wanghao on 16/7/12.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "WH_PastViewController.h"
#import "WH_PastCell.h"
#import "WH_Home.h"
#import "WH_PersonalViewController.h"

@interface WH_PastViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation WH_PastViewController
-(void)viewWillAppear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:NO];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"往期揭晓";
    self.dataArr = [NSMutableArray array];
    [self createEmptylist];
    [self createTab];
    [self postData];
}
-(void)createTab{
    
    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.rowHeight = 180;
    self.myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_myTableView];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view);
        
    }];
    
    //自定义cell Xib注册
    [self.myTableView registerNib:[UINib nibWithNibName:@"WH_PastCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"WH_PastCell"];
    
    
}
-(void)postData{
    
    
    NSString *body = [NSString stringWithFormat:@"action=product_past&product_id=%@",self.pastID];
    [WH_AppTools postUrl:URLstr body:body result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        NSLog(@"=++++%@",result);
        NSDictionary *dic = result;
        NSArray *product_past_array = [dic objectForKey:@"product_past_array"];
        for (NSDictionary *dic in product_past_array) {
            
            WH_Home *past = [WH_Home modelWithDictionary:dic];
            [self.dataArr addObject:past];
        }
        if (_dataArr.count == 0) {
            
            [self bringSubView];
        }
        [self.myTableView reloadData];
    } failure:^(NSError *error) {
        
        
    }];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    static NSString *tabIndex = @"WH_PastCell";
    WH_PastCell *cell = [tableView dequeueReusableCellWithIdentifier:tabIndex];
    cell.pastHome = self.dataArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WH_PersonalViewController *personVC = [[WH_PersonalViewController alloc] init];
    WH_Home *personH = self.dataArr[indexPath.row];
    personVC.personID = personH.user_id;
    personVC.personImg = personH.user_avatar;
    personVC.personName = personH.user_name;
    [self.navigationController pushViewController:personVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
